package www.openteam.com.presenter.business;

import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.InsertStatus;
import www.openteam.com.contract.business.UpdateProductInfoContract;
import www.openteam.com.model.business.UpdateProductInfoModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.business.UpdateProductInfoFragment;

/**
 * Created by kylin on 2016/10/20.
 */

public class UpdateProductInfoPresenter extends BasePresenter<UpdateProductInfoFragment>
        implements UpdateProductInfoContract.UpdateProductInfoPresenter {

    public void updateProductInfo(String code, String name,
                                  String type, String ccode,
                                  String length, String width,
                                  String height, String unit,
                                  String maxstock, String typename,
                                  String CoverPage, String contentpage, String minstock) {

        if (!getIView().checkNull()) {
            ((UpdateProductInfoModel) getiModelMap().get("updateProduct"))
                    .updateProductInfo(code, name, type, ccode, length, width, height, unit, maxstock, typename
                            , CoverPage, contentpage, minstock, new UpdateProductInfoModel.UpdateProductOnListener() {
                                @Override
                                public void updatePISuccess(InsertStatus insertStatus) {
                                    getIView().updatePIData(insertStatus);
                                }

                                @Override
                                public void updatePIFail(Throwable throwable) {
                                    getIView().hidePIData(throwable);
                                }
                            });
        }
    }

    @Override
    public HashMap<String, IModel> getiModelMap() {

        return loadModelMap(new UpdateProductInfoModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("updateProduct", models[0]);

        return hashMap;
    }
}
